var app = getApp();

Page({
  data: {
    luntext: ["房型列表", "酒店详情", "酒店评价"],
    activeIndex: 0,
    imgUrls: [],
    room_id: '0',
    openTime: '',
    decorate_time: ''
  },
  onSlideChangeEnd: function(e) {
    this.setData({
      activeIndex: e.detail.current
    })
  },
  onLoad: function(t) {
    var e = this;
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    }), console.log(t), e.date(), e.setData({
      color: wx.getStorageSync("platform").color,
      grade: wx.getStorageSync("platform").open_member
    });
    e.data.text;
    var a = decodeURIComponent(t.scene);
    if (null != a) var o = t.hotel_id;
    else o = a;
    e.setData({
      room_id: o
    })
    // wx.request({
    //   url: 'http://hotel.tiaze.com/app//?i=3&c=entry&a=wxapp&m=zh_jdgjb&seller_id=' + o + '&do=AssessList',
    //   success: function (t) {
    //     console.log(t.data.data);
    //     e.setData({
    //       score: t.data.data.score,
    //       nums: t.data.data.num
    //     })
    //   }
    // })
    var n = wx.getStorageSync("url");
    e.setData({
      hotel_id: o,
      url: n,
      start: app.util.time(),
      end: app.util.addDate(app.util.time(), 28)
    }), e.refresh();
  },
  commend: function() {
    wx.navigateTo({
      url: './comment?id=' + this.data.room_id
    })
  },
  date: function(t) {
    var e = wx.getStorageSync("day1"),
      a = wx.getStorageSync("day2"),
      o = wx.getStorageSync("day"),
      n = app.util.time();
    if (wx.setStorageSync("datein", i), "" == e) {
      var i = app.util.time();
      wx.setStorageSync("datein", i);
    } else if (e < n) i = n;
    else i = e;
    if ("" == a) var r = app.util.addDate(n, 1);
    else {
      var s = app.util.addDate(n, 1);
      if (a < s) r = s;
      else r = a;
    }
    o = app.util.day(r, i);
    wx.setStorageSync("day1", i), wx.setStorageSync("day2", r), wx.setStorageSync("day", o),
      this.setData({
        datein: i,
        dateout: r,
        time: o,
        current_date: i
      });
  },
  hotel_detail: function(t) {
    wx.navigateTo({
      url: "hotel_detail?hotel_id=" + t.currentTarget.dataset.id
    });
  },
  callPhone: function(e) {
    console.log(e.currentTarget.dataset.id)
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.id
    })
  },
  refresh: function(t) {
    var n = this,
      e = n.data.hotel_id,
      i = n.data.day1;
    app.util.request({
      url: "entry/wxapp/PjDetails",
      cachetime: "0",
      data: {
        seller_id: e
      },
      success: function(t) {
        console.log(t), n.setData({
          hotel: t.data,
          openTime: t.data.open_time ? t.data.open_time.slice(0, 4) : '',
          decorate_time: t.data.decorate_time ? t.data.decorate_time.slice(0, 4) : '',
          imgUrls: t.data.img.split(',')
        });
        console.log(n.data.imgUrls)
      }
    });
    i = wx.getStorageSync("day1");
    var r = app.util.addDate(i, 1);
    console.log(i), console.log(r), app.util.request({
      url: "entry/wxapp/RoomList",
      cachetime: "0",
      data: {
        seller_id: e
      },
      success: function(t) {
        console.log("这是房型列表"), console.log(t);
        var a = t.data,
          e = function(e) {
            app.util.request({
              url: "entry/wxapp/GetRoomCost",
              data: {
                room_id: a[e].id,
                start: i,
                end: r
              },
              success: function(t) {
                console.log(t), a[e].cost = t.data[0].mprice, n.setData({
                  room: a
                });
              }
            }), app.util.request({
              url: "entry/wxapp/GetRoomNum",
              data: {
                room_id: a[e].id,
                start: i,
                end: r
              },
              success: function(t) {
                console.log(t), a[e].room_num = t.data[0].nums, console.log(a[0].room_num), n.setData({
                  room: a
                });
              }
            });
          };
        for (var o in a) e(o);
      }
    }), app.util.request({
      url: "entry/wxapp/AssessList",
      cachetime: "0",
      data: {
        seller_id: e
      },
      success: function(t) {
        for (var e in console.log("这是酒店评价"), console.log(t), t.data) "" != t.data[e].img && (t.data[e].img = t.data[e].img.split(",")),
          t.data[e].time = app.ormatDate(t.data[e].time).slice(0, 10), t.data[e].content = t.data[e].content.replace("↵", "\n");
        n.setData({
          assess_list: t.data.slice(0, 5)
        });
      }
    });
  },
  tabClick: function(t) {
    // this.setData({
    //   activeIndex: t.currentTarget.id
    // });
  },
  bindDateChange1: function(t) {
    console.log("picker发送选择改变，携带值为", t.detail.value);
    var e = this,
      a = t.detail.value,
      o = (e.data.dateout, e.data.current_date, app.util.addDate(a, 1));
    wx.setStorageSync("day1", a), wx.setStorageSync("day2", o), wx.setStorageSync("day", n);
    var n = app.getTime2Time(o, a);
    e.setData({
      datein: t.detail.value,
      dateout: o,
      time: n
    }), this.refresh();
  },
  bindDateChange2: function(t) {
    console.log("picker发送选择改变，携带值为", t.detail.value);
    var e = this.data.datein,
      a = t.detail.value;
    console.log(e + "+" + a);
    var o = app.getTime2Time(a, e);
    wx.setStorageSync("day1", e), wx.setStorageSync("day2", a), wx.setStorageSync("day", o),
      this.setData({
        dateout: t.detail.value,
        time: o
      });
  },
  room_info: function(t) {
    this.data.hotel.id;
    var e = this.data.hotel;
    console.log(e);
    var a = e.tel,
      o = e.coordinates,
      n = e.address,
      i = e.name;
    wx.navigateTo({
      url: "room_info?coordinates=" + o + "&room_id=" + t.currentTarget.dataset.id + "&tel=" + a + "&address=" + n + "&name=" + i + "&price=" + t.currentTarget.dataset.price + "&hotel_id=" + this.data.hotel_id
    });
  },
  order: function(t) {},
  all_comment: function(t) {
    wx.navigateTo({
      url: "all_comment?seller_id=" + this.data.hotel_id
    });
  },
  sele_address: function(t) {
    var o = this.data.hotel,
      n = o.coordinates.split(",");
    wx.getLocation({
      type: "gcj02",
      success: function(t) {
        var e = Number(n[0]),
          a = Number(n[1]);
        wx.openLocation({
          latitude: e,
          longitude: a,
          name: o.name,
          address: o.address
        });
      }
    });
  },
  call_phone: function(t) {
    wx.makePhoneCall({
      phoneNumber: this.data.hotel.tel
    });
  },
  previewImage: function(t) {
    console.log(t);
    var e = this.data.url,
      a = [],
      o = t.currentTarget.id,
      n = t.currentTarget.dataset.index,
      i = this.data.assess_list;
    for (var r in i)
      if (o == i[r].id) var s = i[r].img;
    for (var l in s) a.push(e + s[l]);
    wx.previewImage({
      current: e + s[n],
      urls: a
    });
  },
  formSubmit: function(t) {
    var e = this;
    console.log(t);
    var a = t.detail.formId,
      o = e.data.grade,
      n = e.data.users;
    console.log(n);
    if ("" == n.img) e.setData({
      user_info: !0
    }), app.getUserInfo(function(t) {});
    else if (n.tel == '') {
      wx.showModal({
        content: "请先绑定手机号",
        success: function(t) {
          t.confirm && (console.log("用户点击确定"), wx.navigateTo({
            url: "../register/register"
          }));
        }
      });
    } else {
      var i = wx.getStorageSync("day1"),
        r = wx.getStorageSync("day2");
      console.log(i), console.log(r), 1 == app.time_title(i, r) && (1 == t.detail.target.dataset.classify ? wx.navigateTo({
        url: "../place_order/place_order?room_id=" + t.detail.target.dataset.id + "&hotel_id=" + e.data.hotel_id + "&form_d=" + a
      }) : wx.navigateTo({
        url: "hour_room?room_id=" + t.detail.target.dataset.id + "&hotel_id=" + e.data.hotel_id + "&form_d=" + a + "&cost=" + t.detail.target.dataset.cost + "&rz_time=" + t.detail.target.dataset.rz_time
      }));
    }
  },
  hotel_in: function(t) {
    wx.navigateTo({
      url: "hotel_in?seller_id=" + t.currentTarget.dataset.id
    });
  },
  bindgetuserinfo: function(t) {
    console.log(t), "getUserInfo:fail auth deny" == t.detail.errMsg && wx.showModal({
      title: "",
      content: "您拒绝了个人信息授权，无法正常使用小程序"
    });
  },
  onReady: function() {},
  onShow: function() {
    var e = this;
    app.getUserInfo(function(t) {
      console.log(t), e.setData({
        users: t
      });
    });
  },
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {},
  onShareAppMessage: function() {}
});